package com.atguigu.common.exception;

import com.atguigu.common.result.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

@Slf4j
public class Assert {
    /*断言对象不为空*/
    public static void notNull(Object o , ResponseEnum responseEnum){
        if (o ==null){
            log.info("obj is null...........");
            throw new BusinessException(responseEnum);
        }
    }
/*断言对象为空值*/
    public static void isNull(Object o ,ResponseEnum responseEnum){
        if (o != null){
            log.info("obj is not null.........");
            throw new BusinessException(responseEnum);
        }
    }
    /*断言表达式为真*/
    public static void isTrue(boolean expression ,ResponseEnum responseEnum){
        if (!expression){
            log.info("fail .................");
            throw new BusinessException(responseEnum);
        }
    }
    /*断言两个值不相等*/
    public static void notEquals(Object o1,Object o2 ,ResponseEnum responseEnum){
        if (o1.equals(o2)){
            log.info("equals..................");
            throw new BusinessException(responseEnum);
        }
    }
    /*断言两个对象相等*/
    public static void equals(Object o1,Object o2 ,ResponseEnum responseEnum){
        if (!o1.equals(o2)){
            log.info("notEquals................");
            throw new BusinessException(responseEnum);
        }
    }
    /*断言参数不为空*/
    public static void notEmpty(String s,ResponseEnum responseEnum){
        if (StringUtils.isEmpty(s)){
            log.info("is empty...................");
            throw new BusinessException(responseEnum);
        }
    }
}
